package org.smallmind.scribe.pen;

import java.util.regex.Pattern;

public class RegExpTemplate extends Template {

   private Pattern loggerPattern;

   public RegExpTemplate (String loggerExpression) {

      super();

      loggerPattern = Pattern.compile(loggerExpression);
   }

   public RegExpTemplate (Level level, boolean autoFillLogicalContext, String loggerExpression)
      throws LoggerException {

      super(level, autoFillLogicalContext);

      loggerPattern = Pattern.compile(loggerExpression);
   }

   public RegExpTemplate (Filter[] filters, Appender[] appenders, Enhancer[] enhancers, Level level, boolean autoFillLogicalContext, String loggerExpression)
      throws LoggerException {

      super(filters, appenders, enhancers, level, autoFillLogicalContext);

      loggerPattern = Pattern.compile(loggerExpression);
   }

   public int matchLogger (String loggerName) {

      return loggerPattern.matcher(loggerName).matches() ? Integer.MAX_VALUE : NO_MATCH;
   }
}